package com.dayuanit.dy15.lesson20.demo2;

public class Dog {

    String name;
    int price;

    public Dog() {}

    public Dog(String name, int price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }

        //自己跟自己比
        if (obj == this) {
            return true;
        }

        //我们自己的比较规则
        if (obj instanceof Dog) {
            Dog otherDog = (Dog)obj;//向下转型
            return this.name.equals(otherDog.name) && this.price == otherDog.price;
        }

        return false;
    }
}
